cmake_minimum_required (VERSION 2.6)
project (luge)

set (MANDIR "share/man/man1")
set (BINDIR "bin")

# if both LUA_INC and LUA_LIB are set use them for lua,
# else use the included lua.
if (NOT LUA_INC OR NOT LUA_LIB)
  set (LUA_INC "${CMAKE_SOURCE_DIR}/lua/")
  set (LUA_LIB "${CMAKE_BINARY_DIR}/lua/liblua.a")
  add_subdirectory (lua)
endif (NOT LUA_INC OR NOT LUA_LIB)

# search for gegl via pkg-config
find_package (PkgConfig)

# search for a gegl-version 0.3 or 0.2 (in that order).
foreach (pkg gegl-0.3 gegl-0.2)
  pkg_search_module (gegl ${pkg})
  if (gegl_FOUND)
    set (gegl_pkg ${pkg})
    break ()
  endif (gegl_FOUND)
endforeach (pkg) 

if (gegl_FOUND)
  message ("using GEGL: ${gegl_pkg}")
else (gegl_FOUND)
  message ("no suitable GEGL found." FATAL_ERROR)
endif (gegl_FOUND)

include_directories (${LUA_INC})
include_directories (${gegl_INCLUDE_DIRS})

# describe the main executable luge:
add_executable (luge
  luge-main.cc
  luge-node.cc
  luge-util.cc
  luge-color.cc
  luge-pad.cc
  luge-logging.cc
  options.cc)

target_link_libraries (luge
  ${LUA_LIB} -ldl
  ${gegl_LDFLAGS})

add_dependencies (luge lua)

install (TARGETS luge DESTINATION ${BINDIR})
install (FILES luge.man DESTINATION ${MANDIR} RENAME luge.1)
